from collections import OrderedDict

from django.shortcuts import render

# Create your views here.
from django.views import View

from apps.goods.models import GoodsChannel
from apps.content.models import ContentCategory
from apps.content.utils import get_categories


class IndexView(View):
    '''首页广告'''
    def get(self, request):
        '''提供首页广告界面'''

        categories = get_categories()
        # 广告数据
        contents = {}
        content_categories = ContentCategory.objects.all()
        for cat in content_categories:
            contents[cat.key] = cat.content_set.filter(status=True).order_by('sequence')  # 没有外检的related,只能标准的写法  模型小写_set  获取相关自端

        # print(contents.get('index_lbt')[1].image)  # group1/M00/00/01/CtM3BVrLmiKANEeLAAFfMRWFbY86177278
        # print(contents.get('index_lbt')[1].image.url)  # http://image.meiduo.site:8888/group1/M00/00/01/CtM3BVrLmiKANEeLAAFfMRWFbY86177278

        context = {
            'categories': categories,
            'contents': contents
        }

        return render(request, 'index.html', context)